﻿using System.Collections.Generic;
namespace HtmlParser
{
    public class TagFactory
    {
        

        /// <summary>
        /// Creates the HTML tag.
        /// </summary>
        /// <returns></returns>
        public static HtmlTag CreateHtmlTag(string tagName, List<Attribute> attributes, TagType isEndTag)
        {
            HtmlTagType htmlTagType = TagHelper.ParseTagType(tagName);
            HtmlTag result = null;
            switch (htmlTagType)
            {
                case HtmlTagType.Img:
                    result = new ImgTag();
                    isEndTag = TagType.OpenClose;
                    break;
                case HtmlTagType.A:
                    result = new AnchorTag();
                    break;
                case HtmlTagType.Br:
                    isEndTag = TagType.OpenClose;
                    result = new HtmlTag();
                    break;
                //TODO: Some Embed tab is not work.Plz check it after
                //case HtmlTagType.Embed:
                //    result = new Embed();
                //    break;
                default:
                    result = new HtmlTag();
                    result.IsEndTag = isEndTag;
                    break;
            }

            result.TagName = tagName;
            result.AddAttribute(attributes);
            result.IsEndTag = isEndTag;
            return result;
        }
    }
}
